package com.javaclimb.filmbuy.service;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.javaclimb.filmbuy.dao.CommentInfoDao;
import com.javaclimb.filmbuy.dao.AdvertiserInfoDao;
import com.javaclimb.filmbuy.entity.CommentInfo;
import com.javaclimb.filmbuy.entity.AdvertiserInfo;
import com.javaclimb.filmbuy.entity.TypeInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/*
* 公告信息service层
* */
@Service
public class  AdvertiserInfoService {

    @Resource
    private AdvertiserInfoDao advertiserInfoDao;

    /**
     * 增加一个公告信息
     */
    public AdvertiserInfo add(AdvertiserInfo advertiserInfo){
       advertiserInfo.setTime(new SimpleDateFormat("yyyy--MM--dd HH:mm:ss").format(new Date()));
        advertiserInfoDao.insertSelective(advertiserInfo);
        return advertiserInfo;
    }

    /**
     * 根据主键id删除一个公告信息
     */
    public void delete(Long id){
        advertiserInfoDao.deleteByPrimaryKey(id);
    }

    /**
     * 更新一个公告信息
     */
    public void update(AdvertiserInfo advertiserInfo){

        advertiserInfoDao.updateByPrimaryKeySelective(advertiserInfo);
    }

    /**
     * 根据主键id查询一个公告信息
     */
    public AdvertiserInfo findById(Long id){
        return advertiserInfoDao.selectByPrimaryKey(id);
    }


    /**
     * 根据公告标题模糊查询公告信息对象列表，分页查询
     * @param name 公告标题，不是必选项
     * @param pageNum 要查询第几页
     * @param pageSize 每页多少条数据
     * @return 公告信息列表
     */
    public PageInfo<AdvertiserInfo> findPage(String name, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<AdvertiserInfo> byName = advertiserInfoDao.findByName(name);
        return PageInfo.of(byName);
    }


}












